package ${packageName}.modular.${modular}.controller;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nuxi.core.constant.Constant;
import com.nuxi.core.util.ResponseData;
import ${packageName}.core.annotation.SystemOperateLog;
import ${packageName}.modular.${modular}.pojo.${className};
import ${packageName}.modular.${modular}.pojo.SysUser;
import ${packageName}.modular.${modular}.service.${className}Service;

/**
*	[${remark}]
*/
@RestController
@RequestMapping("/sys/${className?uncap_first}")
public class ${className}Controller {

	@Autowired
	private ${className}Service ${className?uncap_first}Service;
	
	
	/**
	 * 条件查询
	 * 
	 * @param page
	 * @param limit
	 * @return
	 */
	@PostMapping("/list")
	public ResponseData list(
			@RequestParam(value = "page", defaultValue = "1") Integer page, 
			@RequestParam(value = "limit", defaultValue = "20") Integer limit) {

		IPage<${className}> ipage = ${className?uncap_first}Service.list(page, limit);
		return ResponseData.ok(200, "ok", ipage.getRecords(), ipage.getTotal());
	}

	/**
	 * 保存或者修改
	 * 
	 * @param ${modular}
	 * @return
	 */
	@SystemOperateLog(value = "保存或者修改[${remark}]")
	@PostMapping("/saveOrUpdate")
	public ResponseData saveOrUpdate(@RequestBody String json) {
		Boolean result = ${className?uncap_first}Service.insertOrUpdate(JSON.parseObject(json, ${className}.class));
		if (result) {
			return ResponseData.ok(200, "数据保存成功...");
		}
		return ResponseData.fail(4000, "数据保存失败...");
	}

	/**
	 * 查询详情
	 * 
	 * @param id
	 * @return
	 */
	//@SystemOperateLog(value = "根据ID查询[${remark}]")
	@PostMapping("/findById")
	public ResponseData findById(@RequestBody String json) {
		${className} pojo = ${className?uncap_first}Service.getById(JSON.parseObject(json).getString("id"));
		return ResponseData.ok(200, "ok", pojo);
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@SystemOperateLog(value = "根据ID删除[${remark}]")
	@PostMapping("/delete")
	public ResponseData delete(@RequestBody String json) {
		Integer result = ${className?uncap_first}Service.delete(JSON.parseObject(json).getString("id"));
		if (result == 1) {
			return ResponseData.ok(200, "数据删除成功...");
		}
		return ResponseData.fail(4000, "数据删除失败...");
	}
	
	
	/**
	 * 批量删除
	 * 
	 * @param json
	 * @return
	 */
	@SystemOperateLog(value = "批量删除[${remark}]")
	@PostMapping("/batchDelete")
	public ResponseData batchDelete(@RequestBody String json) {
		List<${className}> list = JSON.parseArray(json, ${className}.class);
		int result = ${className?uncap_first}Service.batchDelete(list);
		if (result > 0) {
			return ResponseData.ok(200, "数据删除成功...");
		}
		return ResponseData.fail(4000, "数据删除失败...");
	}
	
	/**
	 * 清空表数据
	 * 
	 * @return
	 */
	@SystemOperateLog(value = "清空[${remark}]表数据")
	@PostMapping("/deleteAll")
	public ResponseData deleteAll() {
		${className?uncap_first}Service.deleteAll();
		return ResponseData.ok(200, "表数据全部清空...");
	}
	
	/**
	 * 禁用 & 启用
	 * 
	 * @param id
	 * @param status
	 * @return
	 */
	@SystemOperateLog(value = "禁用or启用[${remark}]")
	@PostMapping("/status")
	public ResponseData status(@RequestBody String json) {

		Integer result = ${className?uncap_first}Service.status(JSON.parseObject(json).getString("id"), JSON.parseObject(json).getBoolean("status"));
		if (result > 0) {
			return ResponseData.ok(200, "状态修改成功...");
		}
		return ResponseData.fail(4000, "状态修改失败...");
	}
	
	/**
	 * 批量解锁
	 * 
	 * @param json
	 * @return
	 */
	@SystemOperateLog(value = "批量启用 系统用户")
	@PostMapping("/online")
	public ResponseData online(@RequestBody String json) {

		List<${className}> list = JSON.parseArray(json, ${className}.class);
		Integer result = ${className?uncap_first}Service.online(list);
		if (result > 0) {
			return ResponseData.ok(200, "状态修改成功...");
		}
		return ResponseData.fail(4000, "状态修改失败...");
	}
	
	
	/**
	 * 批量锁定
	 * 
	 * @param json
	 * @return
	 */
	@SystemOperateLog(value = "批量禁用[${remark}]")
	@PostMapping("/offline")
	public ResponseData offline(@RequestBody String json) {
		List<${className}> list = JSON.parseArray(json, ${className}.class);
		Integer result = ${className?uncap_first}Service.offline(list);
		if (result > 0) {
			return ResponseData.ok(200, "状态修改成功...");
		}
		return ResponseData.fail(4000, "状态修改失败...");
	}
}
